#include "stdafx.h"
#include "render/font.h"
#include "render/render.h"
#include "SDL_ttf.h"

namespace Render
{

Font* LoadFont(const char* filename, int size)
{
	TTF_Font* pFont = TTF_OpenFont(filename, size);

	return (Font*) pFont;
}

void FreeFont(Font* pFont)
{
	TTF_CloseFont((TTF_Font*) pFont);
}

void DrawText(Render::SurfacePtr pSurface, int x, int y, Font* pFont, const char* pText, U32 rgba)
{
	Surface pTextSurface(DrawToNewSurface(pFont, pText, rgba));

	DrawSprite(pSurface, pTextSurface, x, y);
}

Render::Surface DrawToNewSurface(Font* pFont, const char* pText, U32 rgba)
{
	SDL_Color colour;
	colour.r = (rgba >> 24) & 0xff;
	colour.g = (rgba >> 16) & 0xff;
	colour.b = (rgba >> 8) & 0xff;

	SDL_Surface* pTextSurface = TTF_RenderText_Blended((TTF_Font*) pFont, pText, colour);

	return Render::Surface((Surface_Raw*) pTextSurface);
}

}